package wisp.gui;

//GTGE GUI
import com.golden.gamedev.gui.*;
import com.golden.gamedev.gui.toolkit.*;

//JFC
import java.util.*;
import java.math.*;
import java.awt.Color;

public class InfoWindow extends TFloatPanel{

	private TLabel experience;
	private TLabel perah;
	private TLabel weight;
	
	private int hpPercent;
	private int mpPercent;
	
	private int hpCurrent;
	private int hpMax;
	
	private int mpCurrent;
	private int mpMax;
	
	private TLabel[] hpBar;
	private TLabel[] mpBar;
	private TLabel[] expBar;
	
	private Color hpActiveColor;
	private Color hpDepletedColor;
	private Color mpActiveColor;
	private Color mpDepletedColor;
	
	
	
	public InfoWindow(String name, boolean minimizable, boolean closable, int xpos, int ypos, int xsize, int ysize){
		super(name, minimizable, closable, xpos, ypos, xsize, ysize);
		
		// set about box always in front of other floating panel
    	this.setLayer(this.getLayer() + 1);
    	this.setVisible(true);
		
    	// set text labels
    	
    	//hp
    	TLabel hpText = new TLabel("", 5, 5, 120, 40);
		String text2 = "HP";
		hpText.setText(text2);
		hpText.UIResource().put("Text Vertical Alignment Integer", UIConstants.TOP);
		hpText.UIResource().put("Text Horizontal Alignment Integer", UIConstants.LEFT);
		
		//mp	
		TLabel mpText = new TLabel("", 5, 18, 120, 40);
		String text3 = "MP";
		mpText.setText(text3);
		mpText.UIResource().put("Text Vertical Alignment Integer", UIConstants.TOP);
		mpText.UIResource().put("Text Horizontal Alignment Integer", UIConstants.LEFT);
		
		/////////////////////////
		//exp
		TLabel expText = new TLabel("", 5, 35, 120, 40);
		String text5 = "exp";
		expText.setText(text5);
		expText.UIResource().put("Text Vertical Alignment Integer", UIConstants.TOP);
		expText.UIResource().put("Text Horizontal Alignment Integer", UIConstants.LEFT);
		
		//exp display
		experience = new TLabel("", 45, 35, 120, 40);
		String text6 = "0";
		experience.setText(text6);
		experience.UIResource().put("Text Vertical Alignment Integer", UIConstants.TOP);
		experience.UIResource().put("Text Horizontal Alignment Integer", UIConstants.LEFT);
		/////////////////////////
		
		/////////////////////////
		//money
		TLabel moneyText = new TLabel("", 5, 48, 120, 40);
		String text4 = "Ph";
		moneyText.setText(text4);
		moneyText.UIResource().put("Text Vertical Alignment Integer", UIConstants.TOP);
		moneyText.UIResource().put("Text Horizontal Alignment Integer", UIConstants.LEFT);
		
		//money display
		perah = new TLabel("", 45, 3548, 120, 40);
		String text7 = "100,000,000";
		perah.setText(text7);
		perah.UIResource().put("Text Vertical Alignment Integer", UIConstants.TOP);
		perah.UIResource().put("Text Horizontal Alignment Integer", UIConstants.LEFT);
		/////////////////////////
		
		//create status bars
		hpActiveColor = new Color(0,210,0);
		hpDepletedColor = new Color(150,0,0);
		mpActiveColor = new Color(0,0,210);
		mpDepletedColor = Color.DARK_GRAY;
		
		
		hpBar = new TLabel[100];
		mpBar = new TLabel[100];
		expBar = new TLabel[100];	
		
		updateDataBar(hpBar,8,100,hpActiveColor,hpDepletedColor);
		updateDataBar(mpBar,22,100,mpActiveColor,mpDepletedColor);
		
		
		//add components to panel
		this.add(hpText);
		this.add(mpText);

		this.add(expText);
		this.add(experience);
		this.add(moneyText);
		this.add(perah);
		
		
	}
	
	public void setHP(int hp, int hpmax){
		hpCurrent = hp;
		hpMax = hpmax;
		
		hpPercent = Math.round((hp / hpmax)*100);
		System.out.println("HP is at " + hpPercent + "%");
		
		
		//update text labels
		/*-- here --*/
		
		//update HP bar
		updateDataBar(hpBar, 8, hpPercent, new Color(150,0,0), new Color(0,150,0));
	}
	
	private void updateDataBar(TLabel[] bar, int ypos, int percent, Color activeColor, Color depletedColor){
		
		int xpos = 30;		
		
		//draw active blocks
		for(int i=0; i<percent; i++){
			
			bar[i] = new TLabel("", xpos, ypos, 2, 10);
			bar[i].UIResource().put("Background Color", activeColor);
			
			this.add(bar[i]);
			xpos+=2; //update "cursor" location
			
		}
		
		//draw depleted blocks
		for(int i = percent; i<100; i++)
		{

			bar[i] = new TLabel("", xpos, ypos, 2, 10);
			bar[i].UIResource().put("Background Color", depletedColor);
			//hpBar[i].UIResource().put("Border Stroke", new BasicStroke(1)); 
			//hpBar[i].UIResource().put("Background Border Color", Color.DARK_GRAY);
			
			xpos+=2;
			this.add(bar[i]);

		}
	}
	
	public void cleanDataBar(TLabel[] bar){
		for(int i=0; i<100; i++)
		{
			bar[i].dispose();
		}
	}
	
	public void hPSet(int x){
		cleanDataBar(hpBar);
		updateDataBar(hpBar, 8, x, hpActiveColor, hpDepletedColor);
	}
	
	public void mPSet(int x){
		cleanDataBar(mpBar);
		updateDataBar(mpBar, 22, x, mpActiveColor, mpDepletedColor);
	}
	
	public void expSet(int x){
		experience.setText(((Integer)x).toString());
	}
	

}
